<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>#{msg.TitoloRegistrazione}</title>
        <link href="Style/oneColFixCtrHdr.css" type="text/css" rel="stylesheet"/>
    </h:head>
    <h:body>
        <div class="container">
            <ui:include src="Header.xhtml"/>
            <div class="content">
                <p:outputLabel value="#{msg.titoloFormRegistrazione}"/>
                <h:form>

                    <p:messages id="messaggio" autoUpdate="true" closable="true" />

                    <h:panelGrid id="grid" columns="2">

                        <p:outputLabel value="#{msg.nomeForm}" for="nome"/>
                        <p:inputText id="nome" required="true" validatorMessage="#{msg.nomeValidatorM}" 
                                     requiredMessage="#{msg.nomeRequiredM}" value="#{registrazione.nome}">
                            <f:validateLength minimum="4" />
                        </p:inputText>

                        <p:outputLabel for="cognome" value="#{msg.cognomeForm}"/>
                        <p:inputText id="cognome" required="true" validatorMessage="#{msg.cognomeValidatorM}" 
                                     requiredMessage="#{msg.cognomeRequiredM}" value="#{registrazione.cognome}">
                            <f:validateLength minimum="4"/>
                        </p:inputText>

                        <p:outputLabel for="dataNascita" value="#{msg.dataForm}"/>
                        <p:inputMask id="dataNascita" mask="#{msg.dataMask}" requiredMessage="#{msg.dataRequiredM}" 
                                     required="true" value="#{registrazione.dataNascita}">
                            <f:converter converterId="dataConverter" />
                        </p:inputMask>

                        <p:outputLabel for="numeroTelefono"  value="#{msg.numTelForm}"/>
                        <p:inputMask id="numeroTelefono" mask="#{msg.numTelMask}" value="#{registrazione.numeroTelefono}"/>

                        <p:outputLabel for="codiceFiscale" value="#{msg.codiceFiscaleForm}"/>
                        <p:inputMask id="codiceFiscale" mask="#{msg.codiceFiscaleMask}" validatorMessage="#{msg.codiceFiscaleValidatorM}" 
                                     requiredMessage="#{msg.codiceFiscaleRequiredM}" required="true" value="#{registrazione.codiceFiscale}">
                            <f:validateLength maximum="16" minimum="16"/>
                        </p:inputMask>

                        <p:outputLabel for="provincia" value="#{msg.provinciaForm}"/>
                        <p:selectOneMenu id="provincia" required="true" requiredMessage="#{msg.provinciaRequiredM}"
                                         value="#{provinciaComuni.provincia}" converter="provinciaConverter">
                            <f:selectItem itemValue="" itemLabel="#{msg.selProvincia}" noSelectionOption="true"/>
                            <f:selectItems value="#{provinciaComuni.province}" var="p" itemLabel="#{p.nome},#{p.abbreviazione}" itemValue="#{p}"/>
                            <p:ajax event="valueChange" update="comuni" listener="#{provinciaComuni.handleComuni()}" />
                        </p:selectOneMenu>

                        <p:outputLabel for="comuni" value="#{msg.comuneForm}"/>
                        <p:selectOneMenu id="comuni" required="true" requiredMessage="#{msg.comuneRequiredM}" 
                                         value="#{provinciaComuni.comune}" converter="comuneConverter">
                            <f:selectItem itemLabel="#{msg.selComune}" itemValue="" noSelectionOption="true"/>
                            <f:selectItems value="#{provinciaComuni.comuni}" var="c" itemLabel="#{c.nome},#{c.cap}" itemValue="#{c}"/>
                        </p:selectOneMenu>

                        <p:outputLabel for="via" value="#{msg.viaForm}"/>
                        <p:inputText id="via" required="true" validatorMessage="#{msg.viaValidatorM}" 
                                     requiredMessage="#{msg.viaRequiredM}" value="#{registrazione.via}">
                            <f:validateLength minimum="8"/>
                        </p:inputText>

                        <p:outputLabel for="email" value="#{msg.emailForm}"/>
                        <p:inputText id="email" required="true" requiredMessage="#{msg.emailRequiredM}" value="#{registrazione.email}">
                            <f:validator validatorId="emailValidator"/>
                        </p:inputText>

                        <p:outputLabel for="password" value="#{msg.passwordForm}"/>
                        <p:password id="password" match="confermaPassword" requiredMessage="#{msg.passwordRequiredM}" promptLabel="#{msg.passwordPLabel}" 
                                    weakLabel="#{msg.passwordWLabel}" goodLabel="#{msg.passwordGLabel}" strongLabel="#{msg.passwordSLabel}" 
                                    validatorMessage="#{msg.passwordValidatorM}" required="true" value="#{registrazione.password}" feedback="true" />

                        <p:outputLabel for="confermaPassword" value="#{msg.confPasswordForm}"/>
                        <p:password id="confermaPassword" requiredMessage="#{msg.confPasswordRequiredM}" required="true" value="#{registrazione.password}"/>
                    </h:panelGrid> 
                    <p:outputLabel value="#{msg.infPrivacy}"/><br/>
                    <p:selectOneRadio required="true" value="#{registrazione.accettoTermini}">
                        <f:selectItem itemValue="true" itemLabel="#{msg.accetto}"/>
                        <f:selectItem itemValue="false" itemLabel="#{msg.nonAccetto}"/>
                    </p:selectOneRadio>
                    <p:captcha id="captcha" language="it" required="true" requiredMessage="#{msg.captchaRequiredM}" validatorMessage="#{msg.captchaValidatorM}"/>
                    <p:commandButton update="grid,captcha" action="#{registrazione.registra(provinciaComuni)}" value="#{msg.confermaDati}"/>
                </h:form>
            </div><!-- end content -->
            <ui:include src="Footer.xhtml"/>
        </div><!-- end container -->
    </h:body>
</html>

